﻿using System;
using System.Collections.Generic;
using Assist;
using Autodesk.Revit.DB;
using YJKOpeningCommon.DataEnum;
using YJKOpeningCommon.DbOpening;
using YJKOpeningCommon.OpeningProfile;

namespace YJKOpeningDesignInput.Public
{
	internal class Common
	{
		public static List<double> GetLevel(Autodesk.Revit.DB.Document doc)
		{
			List<double> list = new List<double>();
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
			filteredElementCollector.OfCategory(BuiltInCategory.OST_Levels).WhereElementIsNotElementType();
			foreach (Element element in filteredElementCollector)
			{
				Level level = element as Level;
				if (level != null)
				{
					list.Add(level.Elevation);
				}
			}
			list.Sort();
			return list;
		}

		public static bool RefreshOpeningData(DbOpeningBase opening, Dictionary<string, string> dictionary, ref DbOpeningBase outOpening)
		{
			int num = 0;
			if (int.TryParse(dictionary["CircleToRect"], out num) && 1 != num)
			{
				return false;
			}
			if (opening.m_eHostObject != EHostObject.eArchWall || (opening.m_eCutObject != ECutObject.eHvPipe && opening.m_eCutObject != ECutObject.eWaterPipe && opening.m_eCutObject != ECutObject.ePipeMulti))
			{
				return false;
			}
			OpeningProfileBase profile = opening.m_profile;
			AssistFunc.mmToFeet(300.0);
			OpeningProfileCircle openingProfileCircle = opening.m_profile as OpeningProfileCircle;
			if (openingProfileCircle == null)
			{
				return false;
			}
			outOpening = new DbRectWallOpening();
			OpeningProfileBase openingProfileBase = new OpeningProfileRect();
			OpeningProfileRect openingProfileRect = openingProfileBase as OpeningProfileRect;
			openingProfileRect.m_cutHeight = (openingProfileRect.m_cutWidth = openingProfileCircle.m_dCutDiameter);
			outOpening.m_profile = openingProfileBase;
			if (int.TryParse(dictionary["CircleOpeningOutSize"], out num))
			{
				openingProfileRect.m_dTwoSideExtendDist = AssistFunc.mmToFeet((double)num);
			}
			if (int.TryParse(dictionary["CompositeTolerance"], out num))
			{
				openingProfileRect.m_dTolerance = AssistFunc.mmToFeet((double)num);
			}
			openingProfileBase.m_directionCutObj = profile.m_directionCutObj;
			openingProfileBase.m_directionProfile = profile.m_directionProfile;
			openingProfileBase.m_dPenetrationThickness = profile.m_dPenetrationThickness;
			openingProfileBase.m_position = profile.m_position;
			openingProfileBase.m_HitPosition = profile.m_HitPosition;
			outOpening.m_dHostWidth = opening.m_dHostWidth;
			outOpening.m_eCutObject = opening.m_eCutObject;
			outOpening.m_eHostObject = opening.m_eHostObject;
			outOpening.m_strSpecialty = opening.m_strSpecialty;
			outOpening.m_strAxisX = opening.m_strAxisX;
			outOpening.m_strAxisY = opening.m_strAxisY;
			outOpening.m_strCreateOpeningDate = opening.m_strCreateOpeningDate;
			outOpening.m_strCutUniqueId = opening.m_strCutUniqueId;
			outOpening.m_strDesignDate = opening.m_strDesignDate;
			outOpening.m_strDesignUser = opening.m_strDesignUser;
			outOpening.m_strFloorPlan = opening.m_strFloorPlan;
			outOpening.m_strGuid = default(Guid).ToString();
			outOpening.m_strHostUniqueId = opening.m_strHostUniqueId;
			outOpening.m_strRemark = opening.m_strRemark;
			return true;
		}
	}
}
